<template>
  <transition name="fade">
    <div :id="modalId"
         :class="['modal', {mask: modalController.isFirstModal(modalId)}]"
         :style="modalStyle">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header text-18">
            <div class="modal-title text-color2">
              <slot name="title"/>
            </div>
            <span class="closeBtn" @click="$emit('close')" aria-hidden="true">&times;</span>
          </div>
          <div class="modal-body text-12 text-color2">
            <slot name="body"/>
          </div>
          <div class="modal-footer">
            <slot name="footer"/>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
  import { modalController } from './JS/ModalController';

  export default {
    props: {
      modalId: String,
    },
    data() {
      return {
        modalController,
      }
    },
    computed: {
      modalStyle() {
        return {
          zIndex: modalController.getModal(this.modalId)?.uiArgs.zIndex,
        }
      }
    }
  };
</script>

<style scoped>
  .fade-enter-active {
    animation: fade-in .3s;
  }

  .fade-leave-active {
    animation: fade-in .2s reverse;
  }

  .modal {
    z-index: 1050;
    display: block;
    opacity: 1;
  }

  .mask {
    background-color: rgba(0, 0, 0, .5);
  }

  .modal-dialog {
    animation: transform .3s;
  }

  @keyframes fade-in {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  @keyframes transform {
    from {
      transform: translateY(-100px);
    }
    to {
      transform: translateY(0);
    }
  }
</style>
